﻿
namespace GuessNumberGame
{
class Program
{
static int GenerateRandomNumber(int min, int max)
{
Random random = new Random();
return random.Next(min, max + 1);
}

    static void HandlePlayerGuess(int playerGuess, int randomNumber, ref int guessCount, ref int score)
    {
        if (playerGuess == randomNumber)
        {
            Console.WriteLine("Congratulations! You guessed the correct number.");
            score = 100 - (guessCount * 5);
            if (score < 0)
            {
                score = 0;
            }
            Console.WriteLine($"Your score is: {score}");
        }
        else if (playerGuess < randomNumber)
        {
            Console.WriteLine("Too low. Try again.");
        }
        else
        {
            Console.WriteLine("Too high. Try again.");
        }
        guessCount++;
    }

    static void DisplayGameInstructions()
    {
        Console.WriteLine("Welcome to the Guess Number Game!");
        Console.WriteLine("I'm thinking of a number between 1 and 100.");
        Console.WriteLine("Try to guess the number.");
        Console.WriteLine("For each incorrect guess, you'll lose points.");
        Console.WriteLine("The fewer guesses you make, the higher your score.");
    }

    static void Main(string[] args)
    {
        DisplayGameInstructions();

        int randomNumber = GenerateRandomNumber(1, 100);
        int guessCount = 0;
        int score = 100;

        while (true)
        {
            Console.Write("Enter your guess: ");
            int playerGuess;
            if (int.TryParse(Console.ReadLine(), out playerGuess))
            {
                HandlePlayerGuess(playerGuess, randomNumber, ref guessCount, ref score);
                if (playerGuess == randomNumber)
                {
                    break;
                }
            }
            else
            {
                Console.WriteLine("Invalid input. Please enter a valid number.");
            }
        }

        Console.WriteLine("Thanks for playing!");
    }
}
}